package com.material.mdbook.exception

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.method.ScrollingMovementMethod
import android.view.View
import com.material.mdbook.R
import com.material.mdbook.ui.activity.MainActivity
import kotlinx.android.synthetic.main.activity_show_exception.*


class ShowExceptionActivity : AppCompatActivity(), View.OnClickListener {

    override fun onBackPressed() {

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_show_exception)

        tv_out.isClickable=true
        tv_restart.isClickable=true
        tv_out.setOnClickListener(this)
        tv_restart.setOnClickListener(this)

        initData()
    }

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.tv_out->{
                android.os.Process.killProcess(android.os.Process.myPid())
                System.exit(0)
            }
            R.id.tv_restart->{
                val intent = Intent(this, MainActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                startActivity(intent)
                android.os.Process.killProcess(android.os.Process.myPid())
            }
        }
    }


    private fun initData() {
        tv_cause.movementMethod = ScrollingMovementMethod.getInstance()
        tv_cause.text = "非常抱歉，程序发生异常！请将此界面截图并联系程序员,异常原因如下：" + intent.getStringExtra("exception")
    }
}
